<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="贷款编号" width="220">
        <template slot-scope="scope">
          {{ scope.row.applyNumber }}
        </template>
      </el-table-column>
      <el-table-column label="申请人姓名">
        <template slot-scope="scope">
          {{ scope.row.customerName }}
        </template>
      </el-table-column>
      <el-table-column label="贷款金额">
        <template slot-scope="scope">
          {{ scope.row.loanAmount }}
        </template>
      </el-table-column>
      <el-table-column label="收款银行卡号">
        <template slot-scope="scope">
          {{ scope.row.bankNumber }}
        </template>
      </el-table-column>
      <el-table-column label="还款期限">
        <template slot-scope="scope">
          {{ scope.row.loanTerm }}
        </template>
      </el-table-column>
      <el-table-column label="贷款利率">
        <template slot-scope="scope">
          {{ scope.row.loanRate }}%
        </template>
      </el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-button type="text" @click="doRelease(scope.row.id)">放款审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="放款审批"
      :visible.sync="centerDialogVisible"
      width="30%"
      center>
      <el-input placeholder="请输入放款" v-model="releaseAmount"></el-input>
      <span slot="footer" class="dialog-footer">
    <el-button @click="closeDialog">取 消</el-button>
    <el-button type="primary" @click="comfirmRelease">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import { getListByStatus, applyRelease} from '@/api/loanApi'

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      centerDialogVisible: false,
      checkId: null,
      releaseAmount: null
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getListByStatus({ status: 4 }).then(response => {
        this.list = response.data.records
        this.listLoading = false
      })
    },
    closeDialog() {
      this.centerDialogVisible = false
      this.checkId = null
      this.releaseAmount = null
    },
    comfirmRelease() {
      const params = {
        id: this.checkId,
        releaseAmount: this.releaseAmount
      }
      applyRelease(params).then(response => {
        this.fetchData()
        this.$message('放款成功!')
        this.centerDialogVisible = false
        this.checkId = null
        this.releaseAmount = null
      })
    },
    doRelease(id) {
      this.checkId = id
      this.centerDialogVisible = true
    }
  }
}
</script>
